package javazuoye.one;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/06/27 08:02
 */
public class _2_2_14 {
    static class Node {
        int val;
        Node next;

        public Node() {
        }

        public Node(int val) {
            this.val = val;
        }
    }

    public static void main(String[] args) {
        Node node = new Node(1);
        node.next = new Node(-1);
        node.next.next = new Node(-2);
        node.next.next.next = new Node(0);
        node.next.next.next.next = new Node(3);
        node.next.next.next.next.next = new Node(0);
        node.next.next.next.next.next.next = new Node(-3);
        node.next.next.next.next.next.next.next = new Node(4);
        node.next.next.next.next.next.next.next.next = new Node(4);
        node.next.next.next.next.next.next.next.next.next = new Node(-4);
        node = yes(node);
        while (node != null) {
            System.out.println(node.val);
            node = node.next;
        }
    }

    public static Node yes(Node L) {
        Node res = new Node();
        Node rd = res;
        Node zheng = new Node();
        Node zhengd = zheng;
        Node zero = new Node();
        Node zerod = zero;
        while (L != null) {
            if (L.val == 0) {
                zerod.next = L;
                zerod = zerod.next;
                L = L.next;
                zerod.next = null;
            } else if (L.val < 0) {
                rd.next = L;
                rd = rd.next;
                L = L.next;
                rd.next = null;
            } else {
                zhengd.next = L;
                zhengd = zhengd.next;
                L = L.next;
                zhengd.next = null;
            }
        }
        rd.next = zero.next;
        zerod.next = zheng.next;
        return res.next;
    }

}
